Skip to content

Latest commit

 

History

History
18 lines (15 loc) · 907 Bytes

Pset IO.rst

File metadata and controls

18 lines (15 loc) · 907 Bytes

Write crystals and fingerprints to a file

For large sets of crystals, parsing .CIF files can be slow. The readers in :mod:`.io` yield :class:`.periodicset.PeriodicSet` objects which represent the crystals, and the :class:`.io.SetWriter` and :class:`.io.SetReader` are for writing and reading these crystals to a compressed hdf5 file.

# write the crystals and their AMDs to a file using the crystal's .tags
# amd.SetReader and amd.SetWriter can both be used in context managers
with amd.SetWriter('crystals_and_AMD100.hdf5') as writer:
    for crystal in amd.CifReader('file.cif'):
        crystal.tags['AMD100'] = amd.AMD(crystal, 100)
        writer.write(crystal)

# read back the crystals and their AMDs
crystals = list(amd.SetReader('crystals_and_AMD100.hdf5'))
amds = [crystal.tags['AMD100'] for crystal in crystals]